import fcntl
import sys
import termios

with open( str(sys.argv[1]), 'w') as fd:
 #for char in str(sys.argv[2]) + "\n":
 #for char in eval("'"+raw_input()+"'"):   #    ESC be pressed!
 for char in  eval("'"+sys.argv[2]+"'") : # sudo python zsend.py /dev/pts/18 a\\naa\nhhihi, \\n is ok but \n not. \\e also wrong!!!
   fcntl.ioctl( fd, termios.TIOCSTI, char)

#usage sudo python zsend.py /dev/pts/18 "ihaha"
#                        or /dev/tty2
#sudo python zsend.py /dev/pts/20  oabc\\x1b  ok to send ESC to vi
#                        but too complex: \\x1b:set\\x20nonu\\n
#                                    and: sudo python zsend.py /dev/pts/20  "\\x1b:set nonu\\n" also ok


